<?php

namespace app\admin\controller;

use think\Lang;
use think\Db;

/**
 *服务人员实名认证
 */
class Fupersonaljineng extends AdminControl {

    public function _initialize()
    {
        parent::_initialize();
        Lang::load(APP_PATH . 'admin/lang/'.config('default_lang').'/fupersonal.lang.php');
    }

    /**
     * 列表
     * @return mixed
     */
    public function index()
    {
        $model = model('fujineng');
        $condition =[];
        $condition['ds_fuwu_personal_jineng.status'] = 1;#提交信息,等待认证的
        /**
         * 检索条件
         */
        if (!empty(trim(input('search_phone'))))
        {
            $condition['p.phone'] = array('like','%'.trim(input('search_phone')).'%');
        }
        if (trim(input('search_gc_id1')))
        {
            $condition['ds_fuwu_personal_jineng.cateone'] =trim(input('search_gc_id1'));
        }
        if (trim(input('search_gc_id2')))
        {
            $condition['ds_fuwu_personal_jineng.catetwo'] =trim(input('search_gc_id2'));
        }
        if (trim(input('search_gc_id3')))
        {
            $condition['ds_fuwu_personal_jineng.catrthree'] =trim(input('search_gc_id3'));
        }
        if (trim(input('search_brandid')))
        {
            $condition['ds_fuwu_personal_jineng.brandid'] =array('like','%,'.trim(input('search_brandid')).',%');
        }
        $data =$model->getList($condition,'ds_fuwu_personal_jineng.*,p.phone,g.gc_name as cateonename,g2.gc_name as catetwoname,g3.gc_name as catethreename,b.brand_name',10);
        foreach ($data as $k=>$v){
            $ids = mb_substr(mb_substr($v['brandid'],1),0,-1);
            $brandArr = model('brand')->getBrandList(['brand_id'=>['in',$ids]],'brand_id,brand_name');
            $data[$k]['brandStr'] = implode(',',array_column($brandArr,'brand_name'));
        }
        $brandArr = Db::name('brand')->field('brand_id,brand_name,brand_initial')
            ->where(['brand_apply'=>1])
            ->order('brand_sort desc')->select();
        $this->assign('status', $condition['ds_fuwu_personal_jineng.status'] );
        $this->assign('brandArr',$brandArr);
        $this->assign('search_brandid',trim(input('search_brandid')));

        $class = new \app\common\model\Goodsclass();
        $parent_class_list = $class->getGoodsclassList(['gc_parent_id'=>0]);
        $this->assign('class_list',$parent_class_list);

        $this->assign('data',$data);
        $this->assign('search_gc_id1',trim(input('search_gc_id1')));
        $this->assign('showpage',$model->page_info->render());
        $this->assign('search_phone',trim(input('search_phone')));
        $this->setAdminCurItem('index');
        return $this->fetch();
    }

    /**
     * 成功
     * @return mixed
     */
    public function chenggong()
    {
        $model = model('fujineng');
        $condition =[];
        $condition['ds_fuwu_personal_jineng.status'] = 2;#提交信息,等待认证的
        /**
         * 检索条件
         */
        if (!empty(trim(input('search_phone'))))
        {
            $condition['p.phone'] = array('like','%'.trim(input('search_phone')).'%');
        }
        if (trim(input('search_gc_id1')))
        {
            $condition['ds_fuwu_personal_jineng.cateone'] =trim(input('search_gc_id1'));
        }
        if (trim(input('search_gc_id2')))
        {
            $condition['ds_fuwu_personal_jineng.catetwo'] =trim(input('search_gc_id2'));
        }
        if (trim(input('search_gc_id3')))
        {
            $condition['ds_fuwu_personal_jineng.catrthree'] =trim(input('search_gc_id3'));
        }
        $data =$model->getList($condition,'ds_fuwu_personal_jineng.*,p.phone,g.gc_name as cateonename,g2.gc_name as catetwoname,g3.gc_name as catethreename,b.brand_name',10);
        foreach ($data as $k=>$v){
            $ids = mb_substr(mb_substr($v['brandid'],1),0,-1);
            $brandArr = model('brand')->getBrandList(['brand_id'=>['in',$ids]],'brand_id,brand_name');
            $data[$k]['brandStr'] = implode(',',array_column($brandArr,'brand_name'));
        }
        $brandArr = Db::name('brand')->field('brand_id,brand_name,brand_initial')
            ->where(['brand_apply'=>1])
            ->order('brand_sort desc')->select();
        $this->assign('brandArr',$brandArr);
        $this->assign('search_brandid',trim(input('search_brandid')));
        $this->assign('status', $condition['ds_fuwu_personal_jineng.status'] );

        $class = new \app\common\model\Goodsclass();
        $parent_class_list = $class->getGoodsclassList(['gc_parent_id'=>0]);
        $this->assign('class_list',$parent_class_list);
        $this->assign('search_gc_id1',trim(input('search_gc_id1')));
        $this->assign('data',$data);
        $this->assign('showpage',$model->page_info->render());
        $this->assign('search_phone',trim(input('search_phone')));
        $this->setAdminCurItem('chenggong');
        return $this->fetch('index');
    }
    /**
     * 失败
     */
    public function shibai()
    {
        $model = model('fujineng');
        $condition =[];
        $condition['ds_fuwu_personal_jineng.status'] = 3;#提交信息,等待认证的
        /**
         * 检索条件
         */
        if (!empty(trim(input('search_phone'))))
        {
            $condition['p.phone'] = array('like','%'.trim(input('search_phone')).'%');
        }
        if (trim(input('search_gc_id1')))
        {
            $condition['ds_fuwu_personal_jineng.cateone'] =trim(input('search_gc_id1'));
        }
        if (trim(input('search_gc_id2')))
        {
            $condition['ds_fuwu_personal_jineng.catetwo'] =trim(input('search_gc_id2'));
        }
        if (trim(input('search_gc_id3')))
        {
            $condition['ds_fuwu_personal_jineng.catrthree'] =trim(input('search_gc_id3'));
        }
        $data =$model->getList($condition,'ds_fuwu_personal_jineng.*,p.phone,g.gc_name as cateonename,g2.gc_name as catetwoname,g3.gc_name as catethreename,b.brand_name',10);
        foreach ($data as $k=>$v){
            $ids = mb_substr(mb_substr($v['brandid'],1),0,-1);
            $brandArr = model('brand')->getBrandList(['brand_id'=>['in',$ids]],'brand_id,brand_name');
            $data[$k]['brandStr'] = implode(',',array_column($brandArr,'brand_name'));
        }
        $brandArr = Db::name('brand')->field('brand_id,brand_name,brand_initial')
            ->where(['brand_apply'=>1])
            ->order('brand_sort desc')->select();
        $this->assign('brandArr',$brandArr);
        $this->assign('status', $condition['ds_fuwu_personal_jineng.status'] );
        $this->assign('search_brandid',trim(input('search_brandid')));
        $this->assign('search_gc_id1',trim(input('search_gc_id1')));
        $class = new \app\common\model\Goodsclass();
        $parent_class_list = $class->getGoodsclassList(['gc_parent_id'=>0]);
        $this->assign('class_list',$parent_class_list);
        $this->assign('data',$data);
        $this->assign('showpage',$model->page_info->render());
        $this->assign('search_phone',trim(input('search_phone')));;
        $this->setAdminCurItem('shibai');
        return $this->fetch('index');
    }

    /**
     * 查看详情
     */
    public function view(){
        $model = model('Fujineng');
         if (request()->isPost())
         {
             $data['status']=input('status');
             $data['fail']=input('fail');
             $data['status_admin_id']=session('admin_id');
             $data['status_admin_name']=session('admin_name');
             $data['status_at']=date('Y-m-d H:i:s',time());

            $fuwu_info = db('fuwu_personal')->find(input('fuwuid'));
            #通知内容
            $notif_data = [
                'order_id' =>  '',
                'notif_title' => '技能通知',
                'notif_content' =>  '您提交的技能设置已审核，请及时查看',
                'member_id' => $fuwu_info['id'],
                'member_name' => $fuwu_info['name'],
            ];
            model('points')->saveAfficeslog(2, 1, $notif_data); #服务
            pushMessageToSingle('追加工时通知', $fuwu_info['clientid'], '您提交的技能设置已审核，请及时查看');

             if ($res = $model->edit(['id'=>$_POST['id']],$data))
             {
                 $this->log(lang('ds_update') . lang('fuwu_personal_D') . '技能[' . input('post.id') . ']', 1);
                 dsLayerOpenSuccess(lang('ds_common_save_succ'));
             }else{
                 $this->log(lang('ds_update') . lang('fuwu_personal_D') . '技能[' . input('post.id') . ']', 0);
                 $this->error(lang('ds_common_save_fail'));
             }
         }else {
             $data = $model->info(['id' => input('id')]);
             $this->assign('id', input('id'));
             $this->assign('fuwuid', $data['fuwuid']);
             $this->assign('data', $data);
             return $this->fetch();
         }
    }

    /**
     * 修改状态
     */
    public function edit_status()
    {
        $model = model('Fujineng');
        $condition['id'] = input('id');
        $data[input('column')] = input('value');
        $info = $model->edit($condition,$data);
        if ($info) {
            $this->log(lang('ds_edit') . lang('fuwu_personal_D') . '技能[ID:' . intval(input('id')) . ')', 1);
            ds_json_encode(10000, lang('ds_common_op_succ'));
        }else{
            $this->log(lang('ds_edit') . lang('fuwu_personal_D') . '技能[ID:' . intval(input('id')) . ')', 0);
            ds_json_encode(10001, lang('ds_common_op_fail'));
        }
    }

    public function getCateid($classid)
    {
        $returnArr = [];
        $cateArr =  model('goodsclass')->getGoodsclassInfoById($classid);
        if ($cateArr['gc_parent_id']  == 0)
        {
            $returnArr[1]=$cateArr['gc_id'];
            $returnArr[2]=$cateArr['gc_name'];
            return $returnArr;
        }
        $cate2Arr = model('goodsclass')->getGoodsclassInfoById($cateArr['gc_parent_id']);
        if ($cate2Arr['gc_parent_id']  == 0)
        {
            $returnArr[1]=$cate2Arr['gc_id'];
            $returnArr[2]=$cateArr['gc_id'];
            $returnArr[3]=$cate2Arr['gc_name'].'>'.$cateArr['gc_name'];
            return $returnArr;
        }
        $cate3Arr = model('goodsclass')->getGoodsclassInfoById($cate2Arr['gc_parent_id']);
        if ($cate3Arr['gc_parent_id']  == 0)
        {
            $returnArr[1]=$cate3Arr['gc_id'];
            $returnArr[2]=$cate2Arr['gc_id'];
            $returnArr[3]=$cateArr['gc_id'];
            $returnArr[4]=$cate3Arr['gc_name'].'>'.$cate2Arr['gc_name'].'>'.$cateArr['gc_name'];
            return $returnArr;
        }
    }

    /**
     * 获取卖家栏目列表,针对控制器下的栏目
     */
    protected function getAdminItemList() {
        $menu_array = array(
            array(
                'name' => 'index',
                'text' => '待审核',
                'url' => url('Fupersonaljineng/index'),
            ),
            array(
                'name' => 'chenggong',
                'text' => '审核成功',
                'url' => url('Fupersonaljineng/chenggong'),
            ),
            array(
                'name' => 'shibai',
                'text' => '审核失败',
                'url' => url('Fupersonaljineng/shibai'),
            ),

        );
        return $menu_array;
    }
}


?>
